<template>
	<!--设备管理-->
	<view class="community">
		<view class="head_bg">
			<view class="cu-bar search">
				<view class="search-form bg-white" style="border-radius:50rpx;">
					<text class="cuIcon-search"></text>
					<input type="text" placeholder="" confirm-type="search" @input="getinputvalue"></input>
					 <view @tap="search" class="text-right margin-right-sm text-lg">搜索</view>
				</view>
			</view>
		</view>
		<view class="big_box">
			<view class="big_box_inner">
				<view class="equ_list" @tap="toinfo(info)" v-for="(info,index) in list" :key="index">
					<view class="equ_list_title">
						<view class="equ_list_title_left" style="display: block">{{info.residential_quarters_name}}</view>
						<image class="plot_inner_img" src="../../../common/img/zhankai.png" mode=""></image>
					</view>
					<view class="equ_list_inner1">
						<view class="equ_list_inner_text1">插座个数：{{info.device_total}}个</view>
						<view class="equ_list_inner_text1">正常个数：{{info.device_normal_total}}个</view>
						<view class="equ_list_inner_text1">故障个数：{{info.device_fault_total}}个</view>
						<view class="equ_list_inner_text1">在线个数：{{info.device_online_total}}个</view>
						<view class="equ_list_inner_text1">离线个数：{{info.device_off_total}}个</view>
						<view class="equ_list_inner_text1">正在使用：{{info.device_user_total}}个</view>
					</view>
				</view>
				<view style="height:100rpx;"></view>
				<view v-if="list.length==0" class="margin-top-lg text-center">
					<image src='../../../common/img/no_data.png' style="width:275rpx;height:312rpx;"></image>
				</view>
				<view v-if="list.length>0" class="text-black text-df text-center bg-white padding-sm padding-left-lg be-gray">
					{{loadingTxt}} 共({{list.length}}条记录)
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	let page=1,timer=null
	export default {
		data() {
			return {
				name:'',
				list:[],
				loadingTxt:'加载更多',
			}
		},
		onShow() {
			page=1;
			this.getlist();
		},
		methods: {
			toinfo(info){
				uni.navigateTo({
					url: '/pages/equipment/equipmentList/equipmentList?item='+JSON.stringify(info)
				})
			},
			getinputvalue(e){
				this.name = e.detail.value;
			},
			search(){
				page=1;
				this.getlist();
				this.name='';
			},
			getlist(){
				let that=this;
				that.http.tokenreq({
					url: 'devicemanagement/v1/village',
					data: {
					"pageindex":page,
					'village':this.name
					}
				}).then((res) => {
					console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						let list=e.rows;
						that.list=list;
						page++;
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			},
			getmorelist(){
				this.loadingTxt='加载中'
				let that=this;
				that.http.tokenreq({
					url: 'devicemanagement/v1/village',
					data: {
					"pageindex":page,
					'village':this.name
					}
				}).then((res) => {
					console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						if(e.rows.length==0){
							that.loadingTxt="已经加载全部";
							return;
						}
						that.list=that.list.concat(e.rows);
						page++;
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			},
			onReachBottom() {
				//阻止重复加载
				if(timer !== null){
					clearTimeout(timer)
				}
				timer=setTimeout(()=>this.getmorelist(),500)
				// this.getMoreNews()
			},
		}
	}
</script>
